
\documentclass{beamer}


\mode<presentation>
{
  \usetheme{CambridgeUS}
	\usecolortheme{beaver}
  % or ...

  \setbeamercovered{transparent}
  % or whatever (possibly just delete it)
}


\usepackage{xeCJK}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{times}
\usepackage[T1]{fontenc}
\usepackage{hyperref}
\usepackage{pifont}
\usepackage{bibentry}
\usepackage{verbatim}
\usepackage{color}
\newcommand{\cmark}{\ding{51}}%
\newcommand{\xmark}{\ding{55}}%
\setCJKmainfont{WenQuanYi Micro Hei}
\renewcommand{\raggedright}{\leftskip=0pt \rightskip=0pt plus 0cm}
\raggedright

\let\oldfootnotesize\footnotesize
\renewcommand*{\footnotesize}{\oldfootnotesize\tiny}
\newcommand{\myfootnote}[1]{
    \renewcommand{\thefootnote}{}
    \footnotetext{\scriptsize#1}
    \renewcommand{\thefootnote}{\arabic{footnote}}
}

\title[MongoDB讲义] 
{MongoDB讲义}
\subtitle{MongoDB更新数据（外两则）}

\author[Zhilei Ren] 
{Zhilei Ren}

\institute[OSCAR Team] % (optional, but mostly needed)
{
\\\includegraphics[width=0.2\textwidth]{../utils/logo.jpg}\\
OSCAR Team, School of Software, 
Dalian University of Technology
}


\subject{MongoDB}



\pgfdeclareimage[height=0.5cm]{university-logo}{../utils/logo.jpg}
\logo{\pgfuseimage{university-logo}}



% Delete this, if you do not want the table of contents to pop up at
% the beginning of each subsection:
\AtBeginSubsection[]
{
  \begin{frame}<beamer>{Outline}
    \tableofcontents[currentsection,currentsubsection]
  \end{frame}
}


% If you wish to uncover everything in a step-wise fashion, uncomment
% the following command: 

%\beamerdefaultoverlayspecification{<+->}

\setbeamertemplate{section in toc}[circle]
\setbeamertemplate{items}[circle]
\setbeamertemplate{caption}[numbered]
\setbeamertemplate{bibliography item}{\insertbiblabel}
\setbeamertemplate{bibliography entry title}{}
\setbeamertemplate{bibliography entry journal}{}

\begin{document}

\begin{frame}
  \titlepage
\end{frame}

%\begin{frame}{Outline}
%  \tableofcontents[currentsection,currentsubsection, 
%    hideothersubsections, 
%    sectionstyle=show,
%]
%\end{frame}

\AtBeginSection[]
{
 \begin{frame}<beamer>
 \frametitle{Outline}
 \tableofcontents[currentsection]
 \end{frame}
}
\section{Before Git and MongoDB Today}
\begin{frame}[t]{Vim}
	\begin{block}{Why Vim}
\begin{itemize}
	\item 用于提交commit信息（非必要）
	\item 用于解决冲突（非必要）
	\item 那为什么？
\end{itemize}
	\end{block}
\end{frame}
\begin{frame}[t]{编辑器效率对比}
	\includegraphics[width=.5\textwidth]{vim-learning.jpg}
\end{frame}
\begin{frame}[t]{编辑器效率对比}
	\includegraphics[width=.5\textwidth]{curve.png}
\end{frame}
\begin{frame}[t]{高效编辑}
	\begin{itemize}
		\item 基于模式
		\item 高效移动
		\item 命令组合
		\item 自定义/绑定
	\end{itemize}
\end{frame}
\begin{frame}[t]{Vim模式}
	\centering
	\includegraphics[width=.5\textwidth]{vimmodes.png}
\end{frame}
\begin{frame}[t]{高效移动}
	\centering
	\includegraphics[width=.8\textwidth]{movement.png}
\end{frame}
\begin{frame}[t]{命令与文本对象}
	\begin{block}{命令}
		\begin{itemize}
			\item c: Change
			\item d: Delete
			\item y: Yank
			\item gU: Upper case
			\item gu: Lower case
			\ldots
		\end{itemize}
	\end{block}
	\begin{block}{文本对象}
		\begin{itemize}
			\item aw: a word
			\item iw: inner word
			\item ab: a bracket
			\item ib: inner bracket
			\item at: a tag
			\item it: inner tag
			\ldots
		\end{itemize}
	\end{block}
\end{frame}
\begin{frame}[t]{合体（误）}
	\Huge
	\color{red}{命令}+\color{blue}{移动}/\color{green}{文本对象}
	\large
	\vspace{2cm}
	\begin{itemize}
		\item \color{red}{d}\color{blue}{j}\color{black}: delete current and the next lines
		\item \color{red}{y}\color{blue}\color{blue}0\color{black}: copy to the line head
		\item \color{red}{c}\color{green}iw\color{black}: change inner word
		\item \color{red}{d}\color{green}ab\color{black}: delete a bracket
		\item \color{red}{g}\color{green}Uit\color{black}: change inner tag to lower case
		\ldots
	\end{itemize}
\end{frame}
\begin{frame}[t]{Practise makes perfect}
	\Huge
	无他，唯手熟尔
	\normalsize
	\begin{block}{继续学习}
\begin{itemize}
	\item vimtutor
	\item vimcasts\footnote{\url{http://vimcasts.org/}}
	\item 7 Habits For Effective Text Editing\footnote{\url{http://v.youku.com/v_show/id_XMTIwNDY5MjY4.html?spm=a2h0k.8191407.0.0&from=s1.8-1-1.2}}
	\item Maybe emacs\footnote{\url{https://www.bilibili.com/video/av6048518/?from=search&seid=12030402565005031700}}
\end{itemize}
	\end{block}
	
\end{frame}
\section{Git分支}
\begin{frame}[t]{如何使用Git管理}
	\centering
	\includegraphics[width=.4\textwidth]{git-checkout.png}
	\myfootnote{\url{https://xkcd.com/1597/}}
\end{frame}
\begin{frame}[t]{Git历史版本}
	\begin{block}{git log}
		\tiny
commit 96ee5683a632f0058a583f1159895ae4b8b3b765 (HEAD -> master, origin/master, origin/HEAD)\\
Author: zhilei <zren@dlut.edu.cn>\\
Date:   Wed Sep 20 08:42:20 2017 +0800\\

utils\\

commit 83465639cd5e2e5f9bf48f75933245bcdbe35a2c\\
Author: Zhilei Ren <zren@dlut.edu.cn>\\
Date:   Tue Sep 19 23:42:17 2017 +0800\\

markdown\\

commit b8adbbd13067fc3a0e03b78c82b8a8e4ec079a4e\\
Author: Zhilei Ren <zren@dlut.edu.cn>\\
Date:   Tue Sep 19 23:40:38 2017 +0800\\

href\\
\end{block}

git checkout 8346 检出日志为markdown的版本\\
必要时使用git reflog恢复
\end{frame}
\begin{frame}[t]{commit log十分重要}
	\centering
	\includegraphics[width=.5\textwidth]{git-commit.png}\myfootnote{\url{https://xkcd.com/1296/}}
\end{frame}
\begin{frame}[t,fragile]{Git分支}
	\begin{block}{git branch}
		\small
\begin{verbatim}
git branch experiment
git checkout experiment

#等价于

git checkout -b experiment

#修改分支，提交，然后归并
#blah blah
git add blah
git commit

git checkout master
git merge experiment
git branch -d experiment
\end{verbatim}

	\end{block}
\end{frame}
\section{MongoDB数据更新}
\begin{frame}[t,fragile]{R for Retrieve (CRUD)}
	\begin{block}{准备数据}
		\scriptsize
\begin{verbatim}
//JSON objects
entry1 = {name:"zhangsan", age:30}
entry2 = {name:"lisi", age:40}
entry3 = {name:"zhouwu", age:50, array: [1, 2, 3, 4]}
entry4 = {name:"wangliu", age:60, nested:{x:1, y:"abc"}}

//insert
db.persons.insert(entry1);
db.persons.insert(entry2);
db.persons.insert(entry3);
db.persons.insert(entry4);
\end{verbatim}

	\end{block}
\begin{block}{基本更新}
	\scriptsize
\begin{verbatim}
//basic update
db.persons.update({name: "zhangsan"}, {name:"zhangsan", age:50})
db.persons.update({name: "liuba"}, {name:"liuba", age:10})

//multiple update
db.persons.update({age:{$lte:70}}, {$inc: {age:5}}, {multi:true})

//upsert, aka update or insert if not exists
db.persons.update({name: "liuba"}, {name:"liuba", age:9}, {upsert:true})
\end{verbatim}

\end{block}
	
\end{frame}

\begin{frame}[t,fragile]{更新字段}
	\begin{block}{\$set与\$inc}
		\scriptsize
\begin{verbatim}
//increment operation
db.persons.find({age:{$le:40}})
db.persons.update({age:{$lte:70}}, {$inc: {age:5}})

//set operation
db.persons.update({age:{$gte:60}}, {$set:{age:60}})
\end{verbatim}

	\end{block}
\end{frame}


\begin{frame}[t,fragile]{删除字段}
	\begin{block}{\$unset}
		\scriptsize
\begin{verbatim}

//remove field
db.persons.update({name:"zhouwu"}, {$unset: {array: 1}})
db.persons.update({name:"wangliu"}, {$unset: {"nested.x": 1}})
\end{verbatim}
\end{block}
\end{frame}
\begin{frame}[t,fragile]{操作数组}
	\begin{block}{\$push与\$pop}
		\scriptsize
\begin{verbatim}

//insert document with array
db.persons.insert({'a':[1, 2, 3]})

//push value to field a
db.persons.update({'a': {'$exists': true}}, {'$push': {'a': 4}})
//pop the last value
db.persons.update({'a': {'$exists': true}}, {'$pop': {'a': 1}})
//pop the first value
db.persons.update({'a': {'$exists': true}}, {'$pop': {'a': -1}})
\end{verbatim}
\end{block}
\end{frame}
\end{document}
